package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.entities.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @Author: Daisen.Z
 * @Date: 2021/12/17 14:58
 * @Version: 1.0
 * @Description:
 */
@RestController
@Slf4j
public class OrderController {

    // provider服务的地址
    //private static final String PAYMENT_URL="http://localhost:8001";
    private static final String PAYMENT_URL="http://CLOUD-PAYMENT-SERVICE";


    @Resource
    private RestTemplate restTemplate;

    @GetMapping("/customer/payment/create")
    public CommonResult<Payment> create(@RequestBody Payment payment){
        // 调用8001工程的服务
        return restTemplate.postForObject(PAYMENT_URL+"/payment/create",payment,CommonResult.class);
    }

    @GetMapping("/customer/payment/get/{id}")
    public CommonResult getPaymentById(@PathVariable("id") Long id){
        // 调用8001工程的服务
        return restTemplate.getForObject(PAYMENT_URL+"/payment/get/"+id,CommonResult.class);
    }
}
